package org.erp.product.router;

import org.erp.product.domain.dto.TransferDto;
import org.erp.product.infrastructure.enums.SourceChannelEnum;
import org.erp.product.infrastructure.exception.ProductException;
import org.erp.product.strategy.TransferSourceStrategy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Component
public class TransferSourceFacade {

    @Resource
    private Map<String, TransferSourceStrategy> sourceStrategyMap;

    public void transfer(TransferDto dto) {
        TransferSourceStrategy strategy = sourceStrategyMap.get(SourceChannelEnum.getByCode(dto.getSourceChannel()).name());
        if (strategy == null) {
            throw new ProductException("未知来源");
        }
        strategy.process(dto);
    }
}
